from transformers import  Trainer, DataCollatorForSeq2Seq
# 创建Trainer实例，传入模型、训练参数、训练数据集、数据整理器DataCollatorForSeq2Seq和回调函数
trainer = Trainer(
    model=model,
    args=train_args,
    train_dataset=train_dataset,
    data_collator=DataCollatorForSeq2Seq(tokenizer=tokenizer, padding=True),
    # callbacks=[swanlab_callback],
)
# 开始训练
trainer.train()
